import requests
import app


class LoginApi:
    """登入类"""

    def __init__(self):
        self.login_url = app.BASE_URL + "/api/sys/login"  # 定义登入URL

    def login(self, json_data):  # 登入接口函数
        return requests.post(url=self.login_url, headers=app.HEADERS, json=json_data)


class EmployeeApi:
    """员工管理类"""

    def __init__(self):
        self.add_url = app.BASE_URL + "/api/sys/user"  # 定义添加URL

    def add_emp(self, headers, json_data):
        """员工添加接口"""
        return requests.post(url=self.add_url, headers=headers, json=json_data)

    def check_emp(self, headers, emp_id):
        """员工查看接口"""
        return requests.get(url=self.add_url + '/' + emp_id, headers=headers)

    def update_emp(self, headers, json_data, emp_id):
        """修改员工信息"""
        return requests.put(url=self.add_url + '/' + emp_id, headers=headers, json=json_data)

    def del_emp(self, headers, emp_id):
        """删除员工"""
        return requests.delete(url=self.add_url + '/' + emp_id, headers=headers)

    def check_all_emp(self, headers):
        """查询所有员工"""
        return requests.get(url=self.add_url + "?" + "page=1&size=10", headers=headers)


class DepartmentAPI:
    """部门管理类"""

    def __init__(self):
        """部门接口"""
        self.dept_url = app.BASE_URL + '/api/company/department'

    def dept_add(self, headers, json_data):
        """添加部门"""
        return requests.post(url=self.dept_url, headers=headers, json=json_data)

    def dept_check(self, headers, dept_id):
        """查询部门"""
        return requests.get(url=self.dept_url + '/' + dept_id, headers=headers)

    def dept_update(self, headers, dept_id, json_data):
        """更改部门新"""
        return requests.put(url=self.dept_url + '/' + dept_id, headers=headers, json=json_data)

    def dept_del(self, headers, dept_id):
        """删除部门"""
        return requests.delete(url=self.dept_url + '/' + dept_id, headers=headers)

    def dept_check_all(self, headers):
        """查询全部部门信息"""
        return requests.get(url=self.dept_url + "?" + "page=1&size=10", headers=headers)
